//
//  PywCommonMBProgressHUD+PywCommon.m
//  PywCommonSDKDemo
//
//  Created by Ampaw on 2017/8/12.
//  Copyright © 2017年 Ampaw. All rights reserved.
//

#import "PywCommonMBProgressHUD+PywCommon.h"

@implementation PywCommonMBProgressHUD (PywCommon)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    PywCommonMBProgressHUD *hud = [PywCommonMBProgressHUD showHUDAddedTo:view animated:YES];
    hud.detailsLabelText = text;
    // 设置图片
    UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:icon]];
    hud.customView = imageview;
    // 再设置模式
    hud.mode = PywCommonMBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1.5秒之后再消失
    [hud hide:YES afterDelay:1];
}

#pragma mark 显示提示信息
+ (PywCommonMBProgressHUD *)showMessage:(NSString *)message {
    return [self showMessage:message toView:nil];
}
+ (PywCommonMBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    PywCommonMBProgressHUD *hud = [PywCommonMBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    return hud;
}

#pragma mark - 显示成功信息
+ (void)showSuccess:(NSString *)success {
    [self showSuccess:success toView:nil];
}
+ (void)showSuccess:(NSString *)success toView:(UIView *)view {
    [self show:success icon:@"success" view:view];
}


+ (void)showError:(NSString *)error {
    [self showError:error toView:nil];
}

+ (void)showError:(NSString *)error toView:(UIView *)view {
    [self show:error icon:@"error" view:view];
}

+ (void)hideHUDForView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [self hideHUDForView:view animated:NO];
}

+ (void)hideHUD {
    [self hideHUDForView:nil];
}

@end
